/**
 * Created by ThinkPad on 2018/10/23.
 */
var app = new Vue({
    el:"#vue_app",
    data:{
        bmlx:bmlx,
        avatart:'',
        xy_id:'',
        resList:[],
        checkedImages:new Map()
    },
    methods:{
        savePics: function(){
            var submit_obj = {"xyId":xy_id,imgarrs: ''};
            var checked_array = [];
            let ifcontinue = true;
            app.checkedImages.forEach((value_set,key_str,obj)=>{
                if(value_set.size != 3) {
                    ifcontinue = false;
                    return;
                }
                checked_array = checked_array.concat(Array.from(value_set));
            });
            submit_obj.imgarrs = checked_array.join(",");
            console.log(submit_obj);
            if(ifcontinue == false){
                alert("每天学习的照片需要选择3张，请重新选择！");
                return ;
            }
            $.ajax({
                type: "POST",
                url: baseURL+"/onlinestudy/xcbm/xyxxShExtractImg",
                data: JSON.stringify(submit_obj),
                async: false,
                dataType: "json",
                contentType: "application/json",
                error: function (data) {
                    alert("保存失败");
                },
                success: function (data) {
                    if(data.code == 0) {
                        alert("保存成功");
                    }else{
                        alert(data.msg);
                    }
                }
            });
        },
        checkImage: function(event,imageid,xxdate){
            var checkedImages = app.checkedImages;
            console.log(checkedImages);
            if(event.target.checked){
                checkedImages.get(xxdate).add(imageid);
            }else {
                checkedImages.get(xxdate).delete(imageid);
            }
            console.log(checkedImages);
        },
        onback: function(){
            parent.closeTabByPageId("10001");
        }
    },
    created: function(){
        $.ajax({
            type: "POST",
            url:baseURL+"onlinestudy/xcbm/showImages",
            dataType:"json",
            data:JSON.stringify({bmlx:bmlx,id:xy_id}),
            contentType: "application/json",
            success:function(result){
                if(result.msg == "success") {
                    app.bmlx = result.bmlx;
                    app.resList = result.resList;
                    app.avatart = result.avatart;
                    app.xy_id = result.xy_id;
                    var checkedImages = app.checkedImages;
                    result.resList.forEach(function(value,key,obj){
                        checkedImages.set(value.xxdate, new Set());
                    });
                }else{
                    alert(result.msg);
                }
            }
        });
    }
});